#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QString>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
#include <QFile>
#include <QDebug>
#include <QMessageBox>
#include <QProgressBar>

#include <QBuffer>
#include <QByteArray>
#include <QImageReader>
#include <QTcpServer>
#include <QTcpSocket>
#include <QHostAddress>
#include <QHostInfo>
#include <QNetworkInterface>
#include <QHostAddress>
#include <QList>
#include <QString>
#include <QMessageBox>
#include <QImage>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QGraphicsItem>
#include <iostream>
#include <sys/time.h>

#include <qftp.h>
#include <QtFtp/QFtp>
#include <QtFtp/QtFtp>
#include <QtFtp/qftp.h>
#include <QtFtp/qtftpversion.h>
#include <QtFtp/qurlinfo.h>

/* Opencv库 */
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;

#define DEBUG
#define ShowWindowSizeWidht    640
#define ShowWindowSizeHeight   480

using namespace std;

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();
    void getHostInfo();
    void downloadFile();
    void downLoadFinshed();
    QImage Mat2QImage(const cv::Mat& mat); //Mat转 QImage
    Mat QImage2Mat(QImage image); //QImage转Mat
private:
    Ui::Widget *ui;


public slots:
    void newConnectSlot();//对应于 QTcpServer中有客户端连接会触发newConnect()信号
    void readyReadSlot();//对应于 缓冲区中有数据，会发生readyRead信号

    void ftpDownloadFinished(bool);
    void clientDisconnectSlot();
//    void on_pushButton_clicked();
private:

    QTcpServer *server;//服务器
    QTcpSocket *currentClient;//临时建立连接的客户端
    QString    serverIP;//服务器ip
    uint       serverPort = 9999;//服务器port
    //char       *readBuf; //读缓冲区
    QString    writeBuf;//写缓冲区
    int        clinetNum = 0;

    QRect          rect;
    QGraphicsView  *view;
    QGraphicsScene *scene;
    QGraphicsPixmapItem  item;
    QImage          rec_image;
    QByteArray      array;
    //    QBuffer    buffer;
    Mat frame;

    QNetworkReply *reply;
    QProgressBar *progressBar;
    QFile file;
    QNetworkAccessManager *accessManager;

    QFtp ftp;
    QFile  file_tmp;
protected:
    void closeEvent(QCloseEvent *event);

};

#endif
